package top.fengleifeng.question;

import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;
import top.fengleifeng.util.Constants;

/**
 * @author : fengelfeing
 * @version V1.0
 * @Project: leetcode-test
 * @Package : top.fengleifeng.question
 * @Description:
 * @Date: 2020年11月16日11:44 上午
 */
public class Num406根据身高重建队列 {

    //先排序数字大的在前面，再按照后面那个数字牌
    class Solution {

        public int[][] reconstructQueue(int[][] people) {
            Arrays.sort(people, (o1, o2) -> o1[0] == o2[0] ? o1[1] - o2[1] : o2[0] - o1[0]);
            LinkedList<int[]> list = new LinkedList<>();
            for (int[] i : people) {
                list.add(i[1], i);
            }
            return list.toArray(new int[list.size()][2]);

        }
    }

    public static void main(String[] args) {
        int[][] ints = new int[][]{{7,0}, {7,1}, {6,1}, {5,0}, {5,2}, {4,4}};
        int[][] ints1 = new Num406根据身高重建队列().new Solution().reconstructQueue(ints);
        Constants.printArrs(ints1);
    }
}
